using SimpleJSON;
using UnityEngine;

namespace Gj
{
    public class DeepDataHelper : NodeHelper
    {
        public BindDataType dataType;
        public NodeHelper helper;
        public NodeHelper[] helpers;

        protected override BindDataType bindDataType => dataType;
        
        public override void SetData(JSONObject json)
        {
            if (allData)
            {
                switch (dataType)
                {
                    case BindDataType.String:
                        if (helper != null) helper.SetData(json.Value);
                        for (int i = 0; i < helpers.Length; i++)
                        {
                            helpers[i].SetData(json.Value);
                        }
                        break;
                    case BindDataType.Int:
                        if (helper != null) helper.SetData(json.AsInt);
                        for (int i = 0; i < helpers.Length; i++)
                        {
                            helpers[i].SetData(json.AsInt);
                        }
                        break;
                    case BindDataType.Float:
                        if (helper != null) helper.SetData(json.AsFloat);
                        for (int i = 0; i < helpers.Length; i++)
                        {
                            helpers[i].SetData(json.AsFloat);
                        }
                        break;
                }
            }
            else
            {
                base.SetData(json);
            }
        }

        protected override void BindData(string s)
        {
            if (helper != null) helper.SetData(s);
            for (int i = 0; i < helpers.Length; i++)
            {
                helpers[i].SetData(s);
            }
        }

        protected override void BindData(int i)
        {
            if (helper != null) helper.SetData(i);
            for (int ii = 0; ii < helpers.Length; ii++)
            {
                helpers[ii].SetData(i);
            }
        }

        protected override void BindData(float f)
        {
            if (helper != null) helper.SetData(f);
            for (int i = 0; i < helpers.Length; i++)
            {
                helpers[i].SetData(f);
            }
        }

        protected override void BindData(bool b)
        {
            if (helper != null) helper.SetData(b);
            for (int i = 0; i < helpers.Length; i++)
            {
                helpers[i].SetData(b);
            }
        }

        protected override void BindData(JSONObject obj)
        {
            if (helper != null) helper.SetData(obj);
            for (int i = 0; i < helpers.Length; i++)
            {
                helpers[i].SetData(obj);
            }
        }

        protected override void BindData(JSONArray arr)
        {
            if (helper != null) helper.SetData(arr);
            for (int i = 0; i < helpers.Length; i++)
            {
                helpers[i].SetData(arr);
            }
        }
    }
}